package com.gwnet.shop.controller.api;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.gwnet.common.log.annotation.Log;
import com.gwnet.common.log.enums.BusinessType;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.shop.controller.MBaseController;
import com.gwnet.shop.domain.bo.OrderInfoBo;
import com.gwnet.shop.service.IOrderInfoService;
import com.gwnet.shop.utils.AjaxResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * 订单Controller
 * @author 张万鹏
 * @date 2024-07-29
 */
@RestController
@RequestMapping("/api/orderinfo")
public class OrderInfoApiController extends MBaseController
{
    @Resource
    private IOrderInfoService orderInfoService;


    /**
     * 生成订单信息之前,把所有内容查出来进行展示,方便用户下单
     */
    @SaCheckPermission("shop:orderinfo:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping("/pre")
    public AjaxResult pre(@RequestBody OrderInfoBo orderInfo)
    {
        return success(orderInfoService.preGenerateOrder(orderInfo));
    }

    /**
     * 新增订单
     */
    @SaCheckPermission("shop:orderinfo:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderInfoBo orderInfoBo)
    {
        orderInfoBo.setUserId(LoginHelper.getUserId());
        return toAjax(orderInfoService.insertOrderInfo(orderInfoBo));
    }


}
